Tuesday, September 28, 2004

Callback functions

Callback functions are powerful tools and we should know how to use them...
In general a callback function is a reference to a method that you pass to
another method... When the second method calls the referenced method , it
actually calls back to the first method... This might be a confusing
terminology but a code snippet from MSDN will probably help make it
clearer...

using System;
using System.Runtime.InteropServices;

public delegate bool CallBack(int hwnd, int lParam);

public class EnumReportApp {

[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);

public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}

public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}

Here is the link for you to explore more....
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconusingcallbackfunctions.asp


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

0 Comments:

Post a Comment

<< Home